home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LightWavin' Magazine 2
/
LightWavin' Magazine, Issue 2 (LightWavin' Multimedia)(1997).iso
/
article
/
reduce
/
lod.bml
next >
Wrap
Text File
|
1996-10-14
|
4KB
|
223 lines
/* Level of Detail replacement - By Jason Booth
This script is activated as a BML-OR (object replacement) plugin. It is used
to simulate Level of Detail rendering found in many games, and simulator environments.
The user supplies a list of objects, and at what distances they should be used. During
rendering, the objects are swapped in acourdingly.. Files are saved, and can be recalled
for settings.
*/
var numlevels = 2,loop,f,ours,nfname;
var c[10],c2[10];
var lodID = "";
var newfile[10];
var distance[10];
var c1,c3,c4,c5,c6,items[4],what = 1;
//-----------------------------------------------------------------
// save() is activated when the user saves a scene file where this
// script is active. in save(), we need to store our operating
// parameters into the scene file.
save: what, io
{
getoldfile();
if(what == SCENEMODE)
{
io.writeln(numlevels);
io.writeln(lodID);
do loop = 1 to numlevels
{
io.writeln(newfile[loop]);
io.writeln(distance[loop]);
}
}
}
load: what, io
{
if(what == SCENEMODE)
{
numlevels = number(io.read());
lodID = io.read();
do loop = 1 to numlevels
{
newfile[loop] = io.read();
distance[loop] = number(io.read());
}
savedeffile();
}
}
create
{
do loop= 1 to 10
{
newfile[loop] = "";
distance[loop] = string(loop);
}
distance[1] = 0;
}
options
{
{
reqbegin("Level of Detail replacement plugin, By Jason Booth..");
items[1] = "Load settings";
items[2] = "Edit/save setting";
items[4] = nil;
c1 = addcontrol(what,"What to do:",items);
if (reqpost())
{
what = getvalue(c1);
}
else
return;
if (what == 1)
{
loadlod();
}
if (what == 2)
{
getlevels();
}
f = file(lodID,"w");
f.writeln(numlevels);
do loop = 1 to numlevels
{
f.writeln(newfile[loop]);
f.writeln(distance[loop]);
}
f.close();
reqend();
}
}
getoldfile
{
f = file(lodID,"r");
numlevels = number(f.read());
do loop = 1 to numlevels
{
newfile[loop] = f.read();
distance[loop] = number(f.read());
}
f.close();
}
savedeffile
{
f = file(lodID,"w");
f.writeln(numlevels);
do loop = 1 to numlevels
{
f.writeln(newfile[loop]);
f.writeln(distance[loop]);
}
f.close();
}
process: obj
{
// set first object to one in the scene file.. //
ours = obj.objID;
getoldfile();
distance[1] = 0;
// get camera location, object location, and compare for distance //
var cam,camloc[3],objloc[3],objfname;
cam = getfirstitem(CAMERA);
camloc = cam.param(WPOSITION,obj.newTime);
objloc = ours.param(WPOSITION,obj.newTime);
objfname = obj.curFilename;
var x2,y2,z2,dis;
x2 = (camloc[1]-objloc[1]);
y2 = (camloc[2]-objloc[2]);
z2 = (camloc[3]-objloc[3]);
x2 = pow(x2,2);
y2 = pow(y2,2);
z2 = pow(z2,2);
dis = sqrt(x2+y2+z2);
var level=0; // if level is 0 keep original geometry //
do loop = 1 to numlevels
{
if (dis>=distance[loop])
level = loop;
}
if(level!=0)
nfname = newfile[level];
if (level == 0)
nfname = objfname;
obj.newFilename = nfname;
}
loadlod
{
lodID = getfile("Select a level of detail file","*.lod");
getoldfile();
return;
}
getlevels
{
c3 = addcontrol(numlevels," Number of LOD's");
c4 = addcontrol(lodID," Plugin filename");
if (reqpost())
{
numlevels = getvalue(c3);
lodID = string(getvalue(c4));
}
else
return;
c[1] = addcontrol(newfile[1],"level one is your original object ");
c2[1] = addcontrol(distance[1]," distance to switch should be 0");
do loop=2 to numlevels
{
var st = string("filename for level ",loop);
c[loop] = addcontrol(newfile[loop],st);
c2[loop] = addcontrol(distance[loop]," distance to switch");
}
if (reqpost())
{
do loop = 1 to numlevels
{
newfile[loop] = getvalue(c[loop]);
distance[loop] = getvalue(c2[loop]);
}
}
else
return;
}